﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace SpeechBill
{
    public partial class ClassTend : Form
    {
        public ClassTend()
        {
            InitializeComponent();
        }

        private void ClassTend_Load(object sender, EventArgs e)
        {
            this.loadchartSpline();
            this.loadConsumeType();
        }
        public void loadchartSpline()
        {
            List<string> x = new List<string>();
            List<float> c_money = new List<float>();
            SqlConnection con = DBHelper.GetCon();

            con.Open();
            String cmdText = "select * from consume order by c_day";
            SqlCommand cmd = new SqlCommand(cmdText, con);

            SqlDataReader reader = cmd.ExecuteReader();
            while (reader.Read())
            {
                string time_day = reader["c_day"].ToString();
                int index = time_day.IndexOf("年");
                time_day = time_day.Substring(index+1);
                x.Add(time_day);
                c_money.Add(float.Parse(reader["c_money"].ToString()));
            }

            chart1.Series["日期"].Points.DataBindXY(x, c_money);
            chart1.Series["日期"].IsValueShownAsLabel = true;
            chart1.Series["日期"].MarkerColor = Color.White;
            chart1.Series["日期"].MarkerStyle = System.Windows.Forms.DataVisualization.Charting.MarkerStyle.Square;

            reader.Close();
            con.Close();
        }
        public void loadConsumeType()
        {
            List<string> C_typeData = new List<string>() { "餐饮买菜", "休闲娱乐", "零食饮料", "其他支出" };
            List<int> C_typenum = new List<int>();
            chart2.Series[0].IsValueShownAsLabel = true;
            SqlConnection con = DBHelper.GetCon();

            con.Open();
            String cmdText = "select * from contype";
            SqlCommand cmd = new SqlCommand(cmdText, con);

            SqlDataReader reader = cmd.ExecuteReader();
            
            while (reader.Read())
            {
                C_typenum.Add(int.Parse(reader["typenum"].ToString()));
            }
            chart2.Series[0].Points.DataBindXY(C_typeData, C_typenum);
            chart2.Series[0]["PieLabelStyle"] = "Outside";
        }
        
    }
}
